<?php

/**
 * MVM_MALL 网上商店系统  页面管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-06 $
 * $Id: page.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if($action=='list'){
	require_once MVMMALL_ROOT.'./include/pager.class.php';
    $serch_sql  = false;
	if($ps_st && $ps_ss) {
		$ps_st == 'subject' && $serch_sql  = "WHERE page_subject LIKE '%".filtering($ps_ss)."%'";
		$ps_st == 'name'    && $serch_sql  = "WHERE name LIKE '%".filtering($ps_ss)."%'";
		$ps_st == 'body'    && $serch_sql  = "WHERE page_body LIKE '%".filtering($ps_ss)."%'";
	}
	$total_count = $db->counter("{$tablepre}page_table",$serch_sql);
	$page        = $page ? (int)$page:1;
	$list_num    = 10;
	$rowset      = new Pager($total_count,$list_num,$page);
	$from_record = $rowset->_offset();
	$query       = "SELECT * FROM `{$tablepre}page_table` $serch_sql ORDER BY uid DESC LIMIT $from_record, $list_num";
	$result      = $db->query($query);
	while ( $rt = $db->fetch_array($result)){
		$rt['register_date'] = date($mm_date_format,$rt['register_date']);
		$rt['edit']          = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
		$rt['del']           = "admincp.php?module=$module&action=del&uid=$rt[uid]";
		$page_rt[]           = $rt;
	}
	$page_list = $rowset->link("admincp.php?module=$module&action=list&ps_st=$ps_st&ps_ss=$ps_ss&page=");
	require_once template('page');
	footer();
} elseif ($action=='add') {
	if($setp==1&&$_POST){
		$approval_date  = $use_direct==1 ? $m_now_time : 0;
		$rows = array(
		'page_grant'    => $page_grant,
		'page_name'     => $page_name,
		'use_html'      => $use_html,
		'page_subject'  => $page_subject,
		'page_body'     => $page_body,
		'page_key'      => $page_key,
		'page_desc'     => $page_desc,
		'approval_date' => $approval_date,
		'register_date' => $m_now_time
		);
		$db->insert("{$tablepre}page_table",$rows);
		admin_msg('success',"admincp.php?module=$module&action=list");
	} else {
		require_once MVMMALL_ROOT.'./include/fck/fckeditor.php';
		$oFCKeditor = new FCKeditor('FCKeditor1');
		$oFCKeditor->BasePath = 'include/fck/' ;
		$oFCKeditor->InstanceName = 'page_body' ;
		$oFCKeditor->ToolbarSet = 'Normal' ;
		$oFCKeditor->Width = '100%' ;
		$oFCKeditor->Height = '300' ;
		$html_chk = $dire_chk = 'checked';
		$grade_select = drop_menu($cache->get_cache('grade'),'page_grant');
		require_once template('page_add');
		footer();
	}
} elseif ($action=='edit' && is_numeric($uid)) {
	if($setp==1&&$_POST){
		$approval_date = $use_direct==1 ? $m_now_time : 0;
		$rows = array(
		'page_grant'    => $page_grant,
		'page_name'     => $page_name,
		'use_html'      => $use_html,
		'page_subject'  => $page_subject,
		'page_body'     => $page_body,
		'page_key'      => $page_key,
		'page_desc'     => $page_desc,
		'approval_date' => $approval_date,
		'register_date' => $m_now_time
		);
		$db->update("{$tablepre}page_table",$rows,"uid='$uid'");
		admin_msg('success',"admincp.php?module=$module&action=list");
	} else {
		$page_rt      = $db->get_one("SELECT * FROM `{$tablepre}page_table` WHERE uid = '$uid'");
		@extract($page_rt,EXTR_OVERWRITE);
		$grade_select = drop_menu($cache->get_cache('grade'),'page_grant',$page_grant);
		$html_chk     = $use_html==1      ? 'checked': '';
		$dire_chk     = $approval_date >0 ? 'checked': '';
		require_once MVMMALL_ROOT.'./include/fck/fckeditor.php';
		$oFCKeditor = new FCKeditor('FCKeditor1');
		$oFCKeditor->BasePath = 'include/fck/' ;
		$oFCKeditor->InstanceName = 'page_body' ;
		$oFCKeditor->ToolbarSet = 'Normal' ;
		$oFCKeditor->Width = '100%' ;
		$oFCKeditor->Height = '300' ;
		$oFCKeditor->Value = $page_body;
		require_once  template('page_add');
		footer();
	}
} elseif ($action=='del' && is_numeric($uid)){
	$db->query("DELETE FROM `{$tablepre}page_table` WHERE uid='$uid' ");
} else {
	admin_msg('pass_worng');
}
?>
